function  chooseProject(){
    sessionStorage.setItem("customerName1",$("#ascription_lsit option:selected").text());
    sessionStorage.setItem("customerId1",$("#ascription_lsit option:selected").val());
    sessionStorage.setItem("parentCustomerCode",$('#ascription_lsit option:selected').data('down'));


    if($("#ascription_lsit").val()=='' || $("#ascription_lsit").val()==null){
        $.Huimodalalert('请先选择渠道，再选择渠道的客户！',3000);
        return false;
    }

    /*var chooseData={
        "ascription_lsit":$("#ascription_lsit").val(), //项目编码
        "project_name":$("#project_name").val(), //项目名称
        "tuisongmax":$("#tuisongmax").val(),//所属分公司
        "tuisongmin":$("#tuisongmin").val(),//收货公司名称
        "projectName":$("#projectName").val(),//开票公司名称
        "contact":$("#contact").val(),//开票公司名称
    };
    localStorage.setItem("getArea",$("#getArea").val());
    localStorage.setItem("getPlace",$("#getPlace").val());
    localStorage.setItem("getCity",$("#getCity").val());
    localStorage.setItem("getCountry",$("#getCountry").val());

    localStorage.setItem("chooseData",JSON.stringify(chooseData));*/
    layer_show('选择渠道','chooseChannel.html', 1200, 445);
}



/*获取收货地址*/
discountdata(123);
function discountdata (val) {
    if(val==123){
        //初始化 省
        var user_data = {
            level: '101',
            // memberId:'10258',
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="0"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>';
                    $("#getArea").html(cer);

                }else{
                    var cer="<option value=''>请选择</option>";
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].code+'" data-down="'+tab_data[i].address_id+'">'+tab_data[i].name+'</option>'
                    }
                    $("#getArea").html(cer);
                }
                /*if (localStorage.getItem("getArea")!=null || localStorage.getItem("getArea")!=''){
                    $("#getArea").val(localStorage.getItem("getArea"));
                    localStorage.removeItem("getArea");
                    discountdata(1);
                }*/
            }
        };
        web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
    }else if(val==1){
        //市
        var special=$('#getArea').val();
        if(special==""){
            var cer="<option value=''>请选择</option>"
            $("#getCity").html(cer);

            var cer="<option value=''>请选择</option>"
            $("#getCountry").html(cer);

            var cer="<option value=''>请选择</option>";
            $("#getPlace").html(cer);
        }else {
            var user_data = {
                level: '102',
                // memberId:'10258',
                parentCode:special
            }
            var succCallBack = function (data, status, response) {
                if(data.errorCode=="0"){
                    var tab_data=data.list;
                    if(tab_data==''){
                        cer+='<option value=""></option>';
                        $("#getPlace").html(cer);
                    }else{
                        var cer="<option value=''>请选择</option>";
                        for(var i=0; i<tab_data.length; i++){
                            cer+='<option value="'+tab_data[i].code+'" data-down="'+tab_data[i].address_id+'">'+tab_data[i].name+'</option>'
                        }
                        $("#getPlace").html(cer);

                        var cer="<option value=''>请选择</option>"
                        $("#getCity").html(cer);

                        var cer="<option value=''>请选择</option>"
                        $("#getCountry").html(cer);

                    }
                    /* if (localStorage.getItem("getPlace")!=null || localStorage.getItem("getPlace")!=''){
                         $("#getPlace").val(localStorage.getItem("getPlace"));
                         localStorage.removeItem("getPlace");
                         discountdata(2);
                     }*/
                }
            };
            web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
        }
    }else if(val==2){
        //市
        var special=$('#getPlace').val()
        if(special==""){
            var cer="<option value=''>请选择</option>"
            $("#getCountry").html(cer);

            var cer="<option value=''>请选择</option>"
            $("#getCity").html(cer);
        }else {
            var user_data = {
                level: '103',
                // memberId:'10258',
                parentCode:special
            }
            var succCallBack = function (data, status, response) {
                if(data.errorCode=="0"){
                    var tab_data=data.list;
                    if(tab_data==''){
                        cer+='<option value=""></option>'
                        $("#getCity").html(cer);
                    }else{
                        var cer="<option value=''>请选择</option>";
                        for(var i=0; i<tab_data.length; i++){
                            cer+='<option value="'+tab_data[i].code+'" data-down="'+tab_data[i].address_id+'">'+tab_data[i].name+'</option>'
                        }
                        $("#getCity").html(cer);

                        var cer="<option value=''>请选择</option>";
                        $("#getCountry").html(cer);

                    }
                    /*if (localStorage.getItem("getCity")!=null || localStorage.getItem("getCity")!=''){
                        $("#getCity").val(localStorage.getItem("getCity"));
                        localStorage.removeItem("getCity");
                        discountdata(3);
                    }*/
                }
            };
            web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
        }
    }else if(val==3){
        //市
        var special=$('#getCity').val();
        if(special==""){
            var cer="<option value=''>请选择</option>";
            $("#getCountry").html(cer);
        }else {
            var user_data = {
                level: '104',
                // memberId:'10258',
                parentCode:special
            }
            var succCallBack = function (data, status, response) {
                if(data.errorCode=="0"){
                    var tab_data=data.list;
                    if(tab_data==''){
                        cer+='<option value=""></option>';
                        $("#getCountry").html(cer);
                    }else{
                        var cer="<option value=''>请选择</option>";
                        for(var i=0; i<tab_data.length; i++){
                            cer+='<option value="'+tab_data[i].code+'" data-down="'+tab_data[i].address_id+'">'+tab_data[i].name+'</option>'
                        }
                        $("#getCountry").html(cer);
                    }
                    /*if (localStorage.getItem("getCountry")!=null || localStorage.getItem("getCountry")!=''){
                        $("#getCountry").val(localStorage.getItem("getCountry"));
                        localStorage.removeItem("getCountry");
                    }*/
                }
            };
            web.doAjax(root.member.getLowerAddress,'post',user_data, succCallBack);
        }
    }
}



//渠道
ascription2()
function ascription2() {
    $.ajax({
        type: "post",
        url: root.dockingplatform.allChannelConfig,
        cache: false,  //禁用缓存
        dataType: "json",
        data: {

        },
        success: function (data) {
            console.log(data)
            if(data.errorCode=="0") {
                var dataInter=data.data;
                var interText = doT.template($("#ascription_bob").text());
                $("#ascription_lsit").html(interText(dataInter));
                if (localStorage.getItem("chooseData")!=null){
                    var chooseData = JSON.parse(localStorage.getItem("chooseData"));
                    $("#ascription_lsit").val(chooseData.ascription_lsit);
                    // localStorage.removeItem("chooseData");
                }
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });


}


var inquiry_id = GetQueryString('inquiry_id');
var state = GetQueryString('inquiry_status');
var matcher_id = GetQueryString('matcher_id');
var matching_name = JSON.parse(web.readCookie("loginData")).user.name;
var fix_price_id = GetQueryString('fix_price_id');
var fix_price_name =JSON.parse(web.readCookie("loginData")).user.name;
var customer_id = GetQueryString('customer_id');
var receiver_province = GetQueryString('receiver_province');
var platform = GetQueryString('platform');
var receiver_city = "";

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
};
// 获取询价单信息
/*$.ajax({
    contentType: "application/json",
    type: "POST",
    url: root.xunjiadan.getInquiryManagerList,
    cache: true,  //禁用缓存
    dataType: "json",
    async:false,
    data: JSON.stringify({
        "total":"",
        "totalPage":"",
        "pageNumber":1,
        "pageSize":10,
        startIndex:"",
        select_Manage:{
                "inquiry_id":inquiry_id,
                "customer_name":'',
                "inquiry_status":'',
                "start_time":'',
                "end_time":'',
                "matching_name":'',
                "fix_price_name":'',
                "receiver_province":'',
                "linkman":'',
                "created_time":''
        }
    }),
    success:function (result) {
        var state = result.list[0].inquiry_status;
        var matcher_id =  result.list[0].matcher_id;
        var matching_name = result.list[0].matching_name;
        var fix_price_id = result.list[0].fix_price_id;
        var fix_price_name = result.list[0].fix_price_name;
    },
    error:function (XMLHttpRequest) {
        alert(XMLHttpRequest);
    }
});*/
//获取操作人的姓名及ID
var loginData = JSON.parse(web.readCookie("loginData"));
var service_name = loginData.user.username;
var service_id = loginData.user.user_ID;
// 询价单状态
$('#inquiry_status').text("询价单状态：待匹配");
/*function  getState(state) {
    if(state=='10'||state=='20'){/*
        return '待匹配';
    }else if(state =='30'||state == '40'){
        return  '待定价';
    }else if(state == '50'){
        return '已报价';
    }else if(state == '60'){
        return '已退回';
    }else if(state == '70'){
        return '已撤销';
    };
}*/
// 商品基础信息
var baseParams = {
    "async": true,
    "crossDomain": true,
    "url": root.xunjiadan.getProductInfo,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiry_id": inquiry_id                             //询价单编号
    }
}

$.ajax(baseParams).done(function (result) {
    receiver_city = result.receiver_city;
    $('#inquiry_id').text(result.inquiry_id);
    $('#inquiry_name').text(result.inquiry_name);
    $('#created_time').text(result.created_time);
    $('#collect_address').text(result.receiver_province_name + '/' + result.receiver_city_name + '/' + result.receiver_area_name + '/' + result.street_name);
    $('#linkman').text(result.linkman);
    $('#linkman_phone').text(result.linkman_phone);
    $('#customer_name').text(result.customer_name);
    $('#other_explain').text(result.other_explain);
});
//备注
var remarkParams = {
    "async": true,
    "crossDomain": true,
    "url": root.xunjiadan.getRemarksList,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiry_id": inquiry_id                          //询价单编号
    }
}

$.ajax(remarkParams).done(function (result) {
    var html = '';
    if (result.length > 0) {
        $('#remarkTable').show();
    } else {
        $('#remarkTable').hide();
    }
    for (var i = 0; i < result.length; i++) {
        html += '<tr>'
            + '<td>' + result[i].service_name + '</td>'
            + '<td>' + result[i].result + '</td>'
            + '<td>' + result[i].create_time + '</td>'
            + '<td id="' + result[i].id + '"><a href="javascript:void(0)" class="deleteRemarks">删除</a></td>'
            + '</tr>'
    }
    ;
    $('#remarksList').empty().append(html);
});
//商品附件
var fileParams = {
    "async": true,
    "crossDomain": true,
    "url": root.xunjiadan.getFileList,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiry_id": inquiry_id                          //询价单编号
    }
}

$.ajax(fileParams).done(function (result) {
    var html = '';
    for (var i = 0; i < result.length; i++) {
        if (result[i].file_name == '') {
            var urlName = result[i].file_path;
            var imgUrl = urlName.substring(0, urlName.indexOf('?'));
            result[i].file_name = imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
        }
        if (result[i].file_type == 'pcx' || result[i].file_type == 'emf ' || result[i].file_type == 'gif' || result[i].file_type == 'bmp ' || result[i].file_type == 'jpg' || result[i].file_type == 'tif' || result[i].file_type == 'jpeg ' || result[i].file_type == 'png' || result[i].file_type == 'rle') {
            text = "查看";
        } else {
            text = "下载";
        }
        var strarea = result[i].file_name ;
        var po = strarea.split(".");
        html += '<li>'
            + '<b>附件' + (i + 1) + ':</b>'
            + '<div style="margin-top: -20px;margin-left: 38px;height: 9px;"><a href="' + root.xunjiadan.downLoadFromUrl + '?urlStr=' + encodeURIComponent(result[i].file_path) + '&fileName=' + encodeURIComponent(po[0]) + '">' + text + '</a></div>'
            + '<div class="bg-grey" style="margin-left: 65px;margin-top: -325px;">'
            + '<span>' + result[i].file_name + '</span>'
            + '</div></li>';
    }
    $('#fujian').empty().append(html);
});
//商品清单
var productParams = {
    "async": true,
    "crossDomain": true,
    "url": root.xunjiadan.getProductList,
    "method": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "data": {
        "inquiry_id": inquiry_id                          //询价单编号
    }
};

$.ajax(productParams).done(function (data) {
    console.log(data)
    if (data) {
        var html = '';
        for (var i = 0; i < data.length; i++) {
            var desc=""
            var pic =""
            if(data[i].product_depict!=""){
                desc = JSON.parse(data[i].product_depict).desc;
                pic = JSON.parse(data[i].product_depict).pic;
            }else {
                desc =""
                pic =""
            }


            if (data[i].sku_id && data[i].sku_id != '0') {   // 已匹配
                if (data[i].claim_purchase_time == '1000-01-01') {
                    var claim_purchase_time = '';
                } else {
                    if(data[i].claim_purchase_time=='1000-01-01 00:00:00'){
                        var claim_purchase_time = ""
                    }else {
                        var claim_purchase_time = data[i].claim_purchase_time;
                    }

                }
                if (data[i].claim_arrival_time == '1000-01-01') {
                    var claim_arrival_time = '';
                } else {
                    var claim_arrival_time = data[i].claim_arrival_time;
                }
                html += '<tr id="' + data[i].id + '" belong_inquiry_id="' + data[i].belong_inquiry_id + '">'
                    + '<td class="rfqg_td1">' + (i + 1) + '</td>'
                    + '<td class="rfqg_td2" sku_id="' + data[i].sku_id + '" spu_id="' + data[i].spu_id + '">' + data[i].sku_code + '</td>'
                    + '<td class="rfqg_td3">' + data[i].product_name + '</td>'
                    + '<td class="rfqg_td4">' + data[i].sku_name + '</td>'
                    + '<td class="rfqg_td5">' + data[i].product_classify + '</td>'
                    + '<td class="rfqg_td6">' + data[i].brand + '</td>'
                    + '<td class="rfqg_td7">' + '<img src="' + pic + '"/>' + desc + '</td>'
                    + '<td class="rfqg_td8">' + '<input maxlength="120" value="' + data[i].order_fillrates + '"/>' + '</td>'
                    + '<td class="rfqg_td9" price="' + data[i].price + '">' + data[i].discount_price + '</td>'
                    + '<td class="rfqg_td10">' + '<div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan" maxlength="5"  type="text" class="num_text Numberwo" value="' + data[i].product_count + '"></div>' + '</td>'
                    + '<td class="rfqg_td11">' + data[i].unit_name + '</td>'
                    + '<td class="rfqg_td12">' + data[i].subtotal + '</td>'
                 //   + '<td class="rfqg_td13" product_cycle="' + data[i].product_cycle + '">' + claim_arrival_time + '</td>'
                //    + '<td class="rfqg_td14" created_time="' + data[i].created_time + '" update_time="' + data[i].update_time + '">' + '<input class="workinput wicon input-text radius"  value="' + claim_purchase_time + '" placeholder="要求采购时间" readonly>' + '</td>'
                    + '<td class="rfqg_td15" info_state="' + data[i].info_state + '">'/* + '<a class="matchProduct" href="javascript:void(0);">匹配商品</a>'*/ + '<a href="javascript:void(0);" class="delProduct">删除</a>' + '</td>'
                    + '</tr>'
            } else {
                if (data[i].claim_purchase_time == '1000-01-01') {
                    var claim_purchase_time = '';
                } else {
                    if(data[i].claim_purchase_time=='1000-01-01 00:00:00'){
                        var claim_purchase_time = ""
                    }else {
                        var claim_purchase_time = data[i].claim_purchase_time;
                    }
                }
                if (data[i].claim_arrival_time == '1000-01-01') {
                    var claim_arrival_time = '';
                } else {
                    var claim_arrival_time = data[i].claim_arrival_time;
                }
                html += '<tr id="' + data[i].id + '" belong_inquiry_id="' + data[i].belong_inquiry_id + '">'
                    + '<td class="rfqg_td1">' + (i + 1) + '</td>'
                    + '<td class="rfqg_td2" sku_id="' + data[i].sku_id + '" spu_id="' + data[i].spu_id + '">' + data[i].sku_code + '</td>'
                    + '<td class="rfqg_td3">' + data[i].product_name + '</td>'
                    + '<td class="rfqg_td4">' + '<input value="' + data[i].sku_name + '"/>' + '</td>'
                    + '<td class="rfqg_td5">' + '<input value="' + data[i].product_classify + '"/>' + '</td>'
                    + '<td class="rfqg_td6">' + '<input value="' + data[i].brand + '"/>' + '</td>'
                    + '<td class="rfqg_td7">' + '<img src="' + pic + '"/>' + '<input value="' + desc + '"/>' + '</td>'
                    + '<td class="rfqg_td8">' + '<input  maxlength="120" value="' + data[i].order_fillrates + '"/>' + '</td>'
                    + '<td class="rfqg_td9" price="' + data[i].price + '"></td>'
                    + '<td class="rfqg_td10">' + '<div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan" maxlength="5" type="text" class="num_text Numberwo" value="' + data[i].product_count + '"></div>' + '</td>'
                    + '<td class="rfqg_td11">' + '<input  value="' + data[i].unit_name + '"/>' + '</td>'
                    + '<td class="rfqg_td12"></td>'
                  //  + '<td class="rfqg_td13" product_cycle="' + data[i].product_cycle + '">' + '<input class="workinput wicon input-text radius" value="' + claim_arrival_time + '" placeholder="要求到货时间" readonly/>' + '</td>'
                  //  + '<td class="rfqg_td14" created_time="' + data[i].created_time + '" update_time="' + data[i].update_time + '">' + '<input class="workinput wicon input-text radius" style="width: 129px;"  value="' + claim_purchase_time + '" placeholder="要求采购时间" readonly>' + '</td>'
                    + '<td class="rfqg_td15" info_state="' + data[i].info_state + '">' /*+ '<a class="matchProduct" href="javascript:void(0);">匹配商品</a>'*/ + '<a href="javascript:void(0);" class="delProduct">删除</a>' + '</td>'
                    + '</tr>'
            }
        }
        ;
        $('#productList').empty().append(html);
        /*timeSetMin($('.rfqg_td13>input'));
        timeSetMin2($('.rfqg_td14>input'));*/
    }
});
//添加备注
$('#addRemarks').click(function () {
    var result = $('#remarks').val();
    var create_time = $.nowDate();
    if (result == '') {
        layer.msg('备注不能为空！', {icon: 5, time: 1000});
        return false;
    }
    var addRemParams = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.addRemarks,
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "processData": false,
        "data": JSON.stringify({
            "belong_inquiry_id": inquiry_id,            //询价单编号
            "service_id": service_id,
            "service_name": service_name,
            "service_id": service_id,
            "create_time": create_time,
            "result": result
        })
    }
    $.ajax(addRemParams).done(function (response) {
        $('#remarks').val('');
        if (response.code == '0') {
            $('#remarkTable').show();
            $('#remarksList').append('<tr><td>' + response.service_name + '</td><td>' + response.result + '</td><td>' + response.create_time + '</td><td id="' + response.id + '"><a href="javascript:void(0);" class="deleteRemarks">删除</a></td></tr>');
            layer.msg('添加成功！', {icon: 6, time: 1000});
        } else {
            layer.msg(response.message, {icon: 5, time: 1000});
        }


    });
})
//删除备注
$('#remarkTable').on('click', '.deleteRemarks', function () {
    if (!confirm('确定是否删除？')) {
        return false;
    }
    var Result_id = $(this).parent('td').attr('id');
    var ele = $(this);
    var settings6 = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.deleteRemarks,
        "method": "POST",
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        "data": {
            "Result_id": Result_id
        }
    }

    $.ajax(settings6).done(function (response) {
        if (response.code == '0') {
            layer.msg('删除成功！', {icon: 6, time: 1000});
            ele.parents('tr').remove();
            if ($('#remarksList tr').length == 0) {
                $('#remarkTable').hide();
            }
        } else {
            alert(response.message);
        }
    });
});
$('#productList').on('click', 'tr', function () {
    $(this).addClass('current').siblings('.current').removeClass('current');
})
var row=0;
// 商品删除功能
$('#productList').on('click', '.delProduct', function () {
    /*$(this).parent('td').attr({"info_state": "20"});
    $(this).parents("tr").hide();*/
    // var parent=document.getElementById("productList");
    $(this).parents("tr").remove();
    // parent.removeChild(son);
});
// 商品 匹配商品页面
$('#productList').on('click', '.matchProduct', function () {
    var inquiry_id = $(this).parents('tr').attr('belong_inquiry_id');
    var order = $(this).parents('tr').find('.rfqg_td1').text();
    var sku_id = $(this).parents('tr').find('.rfqg_td2').attr('sku_id');
    if ($(this).parents('tr').find('td.rfqg_td3').children().length > 0) {
        var product_name = $(this).parents('tr').find('td.rfqg_td3 input').val();
    } else {
        var product_name = $(this).parents('tr').find('td.rfqg_td3').text();
    }
    var product_count = $(this).parents('tr').find('td.rfqg_td10 input').val();
    if ($(this).parents('tr').find('td.rfqg_td11 ').children().length > 0) {
        var unit_name = $(this).parents('tr').find('td.rfqg_td11 input').val();
    } else {
        var unit_name = $(this).parents('tr').find('td.rfqg_td11').text();
    }
    if ($(this).parents('tr').find('td.rfqg_td7 ').children().length > 1) {
        var product_depict = $(this).parents('tr').find('td.rfqg_td7 input').val();
    } else {
        var product_depict = $(this).parents('tr').find('td.rfqg_td7').text();
    }
    url = "matchproducts.html?inquiry_id=" + encodeURI(inquiry_id) + '&receiver_province=' + receiver_province + '&platform=' + platform+ '&order=' + order + '&product_count=' + product_count + '&product_name=' + product_name + '&unit_name=' + unit_name + '&product_depict=' + product_depict + '&receiver_city=' + receiver_city + '&customer_id=' + customer_id;
    //防止自由输入项内容含#，getQueryString无法识别
    window.sessionStorage.setItem('product_name', product_name)
    window.sessionStorage.setItem('unit_name', unit_name)
    window.sessionStorage.setItem('product_depict', product_depict)
    title = "匹配商品";
    goNextPage(title, url)
});
// 添加临采商品
$('#temporaryAdd').click(function () {
    var html = '';
    html += '<tr id="" belong_inquiry_id="' + inquiry_id + '">'
        + '<td class="rfqg_td1">' + ($('#productList tr').length + 1) + '</td>'
        + '<td class="rfqg_td2" sku_id="" spu_id=""></td>'
        + '<td class="rfqg_td3"><input/></td>'
        + '<td class="rfqg_td4"><input/></td>'
        + '<td class="rfqg_td5"><input/></td>'
        + '<td class="rfqg_td6"><input/></td>'
        + '<td class="rfqg_td7"><img src = ""/><input/></td>'
        + '<td class="rfqg_td8"><input maxlength="60"/></td>'
        + '<td class="rfqg_td9" price=""></td>'
        + '<td class="rfqg_td10">' + '<div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan" maxlength="5" value="1" type="text"  class="num_text Numberwo" value="' + '' + '"></div>' + '</td>'
        + '<td class="rfqg_td11"><input class="focus"/></td>'
        + '<td class="rfqg_td12"></td>'
       // + '<td class="rfqg_td13" product_cycle=""><input class="workinput wicon input-text radius focus" type="text" placeholder="要求到货时间" readonly></td>'
      //  + '<td class="rfqg_td14" created_time=""><input class="workinput wicon input-text radius focus" style="width: 129px;" type="text" placeholder="要求采购时间" readonly></td>'
        + '<td class="rfqg_td15" info_state="10"><!--<a class="matchProduct" href="javascript:void(0); ">匹配商品</a>--><a class="delProduct" href="javascript:void(0);">删除</a></td>'
        + '</tr>';
    $('#productList').append(html);
   /* timeSetMin($('.rfqg_td13>input'));
    timeSetMin2($('.rfqg_td14>input'));*/
})
// 输入临采商品，表单验证
//商品名称
$('#productList').on('blur', '.rfqg_td3>input', function () {
    var product_name = $(this).val();
    if (product_name == '') {
        layer.msg('商品名称为必填！', {icon: 5, time: 1000});

    }
})
//数量
// 减数量
function number_decrease(el) {
    var num = $(el).next().next().val(); //当前数量
    if (num > 1) {
        $(el).next().next().val(parseInt(num) - 1);
        var price = $(el).parents('td').prev('td').text(); //单价
        if (price == '' || price == 0 || price == undefined) {
            return false;
        } else {
            price = parseFloat(price);
        }
        $(el).parents('tr').find('.rfqg_td12').text((price * (parseInt(num) - 1)).toFixed(2));
    } else {
        layer.msg('已是最小值', {icon: 5, time: 1000});
    }
}

// 加数量
function number_increase(el) {
    var num = $(el).next().val(); //当前数量
    if (num < 99999) {
        $(el).next().val(parseInt(num) + 1);
        var price = $(el).parents('td').prev('td').text(); //单价
        if (price == '' || price == 0 || price == undefined) {
            return false;
        } else {
            price = parseFloat(price);
        }
        $(el).parents('tr').find('.rfqg_td12').text((price * (parseInt(num) + 1)).toFixed(2));
    } else {
        layer.msg('已是最大值', {icon: 5, time: 1000});
    }
}

$('#productList').on('input propertychange', '.rfqg_td10 input', function () {
    var product_count = $(this).val();
    if (product_count == '') {
        $(this).val(1);
    }
    var reg = /^\+?[1-9][0-9]*$/;
    if (!reg.test(product_count)) {
        layer.msg('数量为正整数！', {icon: 5, time: 1000});
        $(this).val('1');
        var price = $(this).parents('td').prev('td').text();//单价
        if (price == '' || price == 0 || price == undefined) {
            return false;
        } else {
            price = parseFloat(price);
        }
        $(this).parents('tr').find('.rfqg_td12').text((price * 1).toFixed(2));
        return false;
    }
    if (product_count > 99999) {
        layer.msg('数量不能大于99999！', {icon: 5, time: 1000});
    }
    // 小计
    var num = parseInt($(this).val());
    var price = $(this).parents('td').prev('td').text();//单价
    if (price == '' || price == 0 || price == undefined) {
        return false;
    } else {
        price = parseFloat(price);
    }
    $(this).parents('tr').find('.rfqg_td12').text((price * num).toFixed(2));
})
//单位
$('#productList').on('blur', '.rfqg_td11>input', function () {
    var unit_name = $(this).val();
    if (unit_name == '') {
        alert('单位为必填！');
        return false;
    }
})
//释放
var isIng = false;
$('#release').click(function () {
    if(isIng){
        layer.msg('请求已提交，请勿重复点击！');
        return false;
    }
    isIng = true;
    var back = "2";
    var productData = getPorductList();
    var all_number = productData.all_number;
    var info = productData.info;
    var exist_price_number = productData.exist_price_number;
    var manage = getManage(inquiry_id, all_number, exist_price_number);
    var orderProductsParams = {
        "async": true,
        "crossDomain": true,
        "url": root.dockingplatform.orderCheckUpdate,
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": JSON.stringify({
            "manage": manage,
            "info": info,
            "enterChange": {
                "inquiry_id": inquiry_id,
                "back": back,
                "state": state,
                "matcher_id": matcher_id,
                "matching_name": matching_name,
                "fix_price_id": '',
                "fix_price_name": ''
            }
        })
    }
    $.ajax(orderProductsParams).done(function (response) {
        if (response.code == '0') {
            //$('#ReleasedSuccessfully').modal('show');
            layer.msg('释放成功', {icon: 6, time: 1000});
        } else if (response.code == '60') {
            layer.msg('该询价单已退回！', {icon: 5, time: 1000});
        } else if (response.code == '70') {
            layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
        } else {
            $.Huimodalalert('请完善数据', 2000);
            return false;
        }
        setTimeout(function () {
            window.parent.doSubmit();
            var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
            parent.layer.close(index);
        }, 1000)
    });
});

// 临采商品
$('#temporarySelect').click(function () {
    //判断是否有临采商品
    var flag = false; //false 没有临采商品不可以点击
    $('#productList tr').each(function (i, dom) {
        if (($(this).find('td.rfqg_td2').attr('sku_id') == '0' || $(this).find('td.rfqg_td2').attr('sku_id') == '' || $(this).find('td.rfqg_td2').attr('sku_id') == undefined)&&$(this).find('td.rfqg_td15').attr("info_state")==10){
            console.log($(this))
            flag = true;
            return false;
        }
    });
    if (!flag) {   // 无临采商品
        layer.msg('无临采商品！', {icon: 6, time: 1000});
        return false;
    }
    // 判断临采商品是否已匹配
    var bool = false;  //false 已匹配
    $('#productList tr').each(function (i, dom) {
        if ($(dom).find('.rfqg_td9').text() == 0) {
            bool = true;   // true 未匹配
            return false;
        }
    });
    if (bool) {
        layer.confirm('询价单存在临采商品，将待定价，您确定吗？', {
            btn: ['确定', '返回'] //按钮
        }, function (index, layero) {
            //必填项
            layer.close(index);
            var isPass = true;
            var productList = $('#productList tr');
            var nameList = [];
            var maop=[]
            var plm={}
            console.log(productList)
            for(var j=0;j<productList.length;j++) {
                if ($(productList[j]).find('.rfqg_td7 input').val() != undefined && $(productList[j]).find('.rfqg_td4 input').val() != undefined){
                    plm = {
                        "name": $(productList[j]).find('.rfqg_td7 input').val() + $(productList[j]).find('.rfqg_td4 input').val(),
                    }
                }else {
                    console.log($(productList[j]).find('.rfqg_td4 ').html())
                    console.log($(productList[j]).find('.rfqg_td7 ').html())
                    plm = {
                        "name": $(productList[j]).find('.rfqg_td7 ').html() + $(productList[j]).find('.rfqg_td4 ').html(),
                    }
                }
                if($(productList[j]).find('.rfqg_td15').attr("info_state")==10){
                    maop.push(plm)
                }


            }


            productList.each(function (index, dom) {


                if (($(dom).find('td.rfqg_td2').attr('sku_id') == '' || $(dom).find('td.rfqg_td2').attr('sku_id') == '0') && $(dom).find('td.rfqg_td15').attr('info_state') == '10') {
                    if ($(dom).find('.rfqg_td3 input').val() == '') {
                        layer.msg('临采商品名称不能为空！', {icon: 5, time: 1000});
                        isPass = false;
                        return false;
                    }
                    if ($(dom).find('.rfqg_td4 input').val() == '') {
                        layer.msg('平台商品名称不能为空！', {icon: 5, time: 1000});
                        isPass = false;
                        return false;
                    } else {
                        nameList.push($(dom).find('.rfqg_td4 input').val())
                    }
                    if ($(dom).find('.rfqg_td10 input').val() == '') {
                        layer.msg('临采商品数量不能为空！', {icon: 5, time: 1000});
                        isPass = false;
                        return false;
                    }
                    if ($(dom).find('.rfqg_td11 input').val() == '') {
                        layer.msg('临采商品单位不能为空！', {icon: 5, time: 1000});
                        isPass = false;
                        return false;
                    }
                    if ($(dom).find('.rfqg_td13 input').val() == '') {
                        layer.msg('要求到货时间不能为空！', {icon: 5, time: 1000});
                        isPass = false;
                        return false;
                    }
                    if ($(dom).find('.rfqg_td14 input').val() == '') {
                        layer.msg('要求采购时间不能为空！', {icon: 5, time: 1000});
                        isPass = false;
                        return false;
                    }
                }
                /*    if($(dom).find('.rfqg_td7 input').val()!=undefined &&$(dom).find('.rfqg_td4 input').val()!= undefined){
                        if($(dom).find('.rfqg_td7 input').val()==$(dom).find('.rfqg_td4 input').val()){
                            layer.msg('平台商品名称+商品描述存在相同条目！', {icon: 5, time: 1000});
                            isPass = false;
                            return false;
                        }
                    }else {
                        if($(dom).find('.rfqg_td7 ').text()==$(dom).find('.rfqg_td4 ').text()){
                            layer.msg('平台商品名称+商品描述存在相同条目！', {icon: 5, time: 1000});
                            isPass = false;
                            return false;

                        }
                    }*/
            });
            $.each(maop,function(i,first){
                $.each(maop,function(s,sed){
                    if (i==s){
                        return true;
                    }

                    if(first.name!=""||sed.name!=""){
                        if (first.name==sed.name){
                            layer.msg('平台商品名称+商品描述存在相同条目！', {icon: 5, time: 1000});
                            isPass = false;
                            return false;

                        }

                    }

                })
            })

            console.log(nameList);
            /*  var nary=nameList.sort();
              for(var i=0;i<nameList.length;i++) {
                  if (nary[i] == nary[i + 1]) {
                      $.Huimodalalert('平台商品名称重复!', 2000);
                      return;
                  }
              }*/
            if (!isPass) {
                return false;
            }
            // 确定的回调
            var back = "4";
            var productData = getPorductList();
            var all_number = productData.all_number;
            var info = productData.info;
            var exist_price_number = productData.exist_price_number;
            var manage = getManage(inquiry_id, all_number, exist_price_number);
            var orderProductsParams = {
                "async": true,
                "crossDomain": true,
                "url": root.dockingplatform.orderCheckUpdate,
                "method": "POST",
                "headers": {
                    "Content-Type": "application/json"
                },
                "data": JSON.stringify({
                    "manage": manage,
                    "info": info,
                    "enterChange": {
                        "inquiry_id": inquiry_id,
                        "back": back,
                        "state": state,
                        "matcher_id": matcher_id,
                        "matching_name": matching_name,
                        "fix_price_id": '',
                        "fix_price_name": ''
                    }
                })
            }
            $.ajax(orderProductsParams).done(function (response) {
                if (response.code == '0') {
                    layer.msg('商品已转为待定价！', {icon: 6, time: 1000});
                    setTimeout(function () {
                        window.parent.doSubmit();
                        var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                        parent.layer.close(index);
                    }, 1000)

                } else if (response.code == '70') {
                    layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
                    setTimeout(function () {
                        window.parent.doSubmit();
                        var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                        parent.layer.close(index);
                    }, 1000)
                }else {
                    $.Huimodalalert(response.msg, 2000);
                }
            });
        }, function () {
        });
    } else {
        layer.msg('商品已全部匹配成功，请选择报价完成', {icon: 6, time: 1000});
    }
});

// 报价完成
$('#quotationCompletion').click(function () {
    var productList = getPorductList();
    all_number = productList.all_number;
    exist_price_number = productList.exist_price_number;
    if (parseInt(all_number) - parseInt(exist_price_number) > 0) {
        layer.confirm('您还有' + (parseInt(all_number) - parseInt(exist_price_number)) + '个商品未报价，您确定要完成报价吗？', {
            btn: ['确定', '返回'] //按钮
        }, function (index, layero) {
            layer.close(index);
            quotationCompletionCallback();
        }, function () {
        });
    }
    if (parseInt(all_number) - parseInt(exist_price_number) == 0) {
        layer.confirm('您确定要完成报价吗?', {
            btn: ['确定', '返回'] //按钮
        }, function (index, layero) {
            layer.close(index);
            quotationCompletionCallback();
        }, function () {
        });
    }
});

// 点询问框之后   报价完成 ajax
function quotationCompletionCallback() {
    var back = "5";
    var productData = getPorductList();
    var all_number = productData.all_number;
    var info = productData.info;
    var exist_price_number = productData.exist_price_number;
    var manage = getManage(inquiry_id, all_number, exist_price_number);
    var params = {
        "async": true,
        "crossDomain": true,
        "url": root.dockingplatform.orderCheckUpdate,
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": JSON.stringify({
            "manage": manage,
            "info": info,
            "enterChange": {
                "inquiry_id": inquiry_id,
                "back": back,
                "state": state,
                "matcher_id": matcher_id,
                "matching_name": matching_name,
                "fix_price_id": fix_price_id,
                "fix_price_name": fix_price_name
            }
        })
    }
    $.ajax(params).done(function (response) {
        if (response.code == '0') {
            layer.msg('询价单报价完成！', {icon: 6, time: 1000});
            setTimeout(function () {
                window.parent.doSubmit();
                var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                parent.layer.close(index);
            }, 1000)

        } else if (response.code == '70') {
            layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
            setTimeout(function () {
                window.parent.doSubmit();
                var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                parent.layer.close(index);
            }, 1000)
        } else {
            $.Huimodalalert('请完善数据', 2000);
        }
    });
}
// 保存功能
var isSave = false;
$('#save').click(function () {
    if($("#ascription_lsit option:selected").text()==null || $("#ascription_lsit option:selected").val()==undefined || $("#ascription_lsit option:selected").val()==''){
        layer.msg('请选择渠道商！', {icon: 5, time: 1000});
        return false;
    }

    if($("#customer_name").val()==null || $("#customer_name").val()==undefined || $("#customer_name").val()==''){
        layer.msg('请选择渠道客户！', {icon: 5, time: 1000});
        return false;
    }
    if($("#linkman").val()==null || $("#linkman").val()==undefined || $("#linkman").val()==''){
        layer.msg('请填写询价联系人！', {icon: 5, time: 1000});
        return false;
    }

    if($("#linkman_phone").val()==null || $("#linkman_phone").val()==undefined || $("#linkman_phone").val()==''){
        layer.msg('请填写询价联系电话！', {icon: 5, time: 1000});
        return false;
    }

    if($("#getCity option:selected").text()==null || $("#getCity option:selected").val()==undefined || $("#getCity option:selected").val()==''){
        layer.msg('请填写请选择询价地址！', {icon: 5, time: 1000});
        return false;
    }



    if (isSave) {
        return false;
    }
    var bool = true;
    console.log("12123",$('#productList>tr').length);
    if ($('#productList>tr').length==0){
        layer.msg('临采商品不能为空！', {icon: 5, time: 1000});
        return false;
    }

    for (var i = 0; i < $('#productList>tr').length; i++) {
        var item = $($('#productList>tr')[i]);
        var product_name1=item.find('.rfqg_td4 input').val();
        if (product_name1=='' || product_name1==null) {
            layer.msg('平台商品名称必填！', {icon: 5, time: 1000});
            return false;
        }
    }

   /* for (var i = 0; i < $('#productList>tr').length; i++) {
        var item = $($('#productList>tr')[i]);
        var product_name1=item.find('.rfqg_td13 input').val();
        if (product_name1=='' || product_name1==null) {
            layer.msg('请填写要求到货时间！', {icon: 5, time: 1000});
            return false;
        }
    }*/

    for (var i = 0; i < $('#productList>tr').length; i++) {
        var item = $($('#productList>tr')[i]);
        var product_name1=item.find('.rfqg_td11 input').val();
        if (product_name1=='' || product_name1==null) {
            layer.msg('临采商品单位不能为空！', {icon: 5, time: 1000});
            return false;
        }
    }

    /*for (var i = 0; i < $('#productList>tr').length; i++) {
        var item = $($('#productList>tr')[i]);
        var product_name1=item.find('.rfqg_td14 input').val();
        if (product_name1=='' || product_name1==null) {
            layer.msg('请填写要求采购回复时间！', {icon: 5, time: 1000});
            return false;
        }
    }*/

    if ($("#timemin").val() == '') {
        layer.msg('要求到货时间不能为空！', {icon: 5, time: 2000});
        isPass = false;
        return false;
    }
    if ($("#timemax").val() == '') {
        layer.msg('要求采购时间不能为空！', {icon: 5, time: 2000});
        isPass = false;
        return false;
    }


    if (bool) {
        var callback = function (response) {
            if (response.errorCode == 0) {
                isSave = true;
                showmsg(response.msg,6);
                /*setTimeout(function () {
                    location.reload();
                }, 1000);*/
                /*setTimeout(function () {
                    var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                    parent.layer.close(index);
                },1000)*/
            }  else {
                $.Huimodalalert(response.msg, 2000);
            }
        };

        doSave(callback);
    } else {
        return false;
    }
});

// 提示信息
function showmsg(msg,icon){
    layer.msg(msg, {
        icon:icon,
        time: 1000
    },function(){
        if(icon==6){
            var index = parent.location.reload();
            parent.layer.close(index);
        }
    });
}

function myChoose(){
    $('#customer_name').val('');
}

// 退回
$('#return').click(function () {
    //$('#ReturnReason').modal('show');
    var html = '<label style="margin-left:20px;vertical-align: top;line-height: 56px;"><span class="require">*</span>询价单退回原因：</label><textarea rows="10" id="back_reason" style="width:300px;height:155px;margin-top: 20px;"></textarea>'
    layer.open({
        type: 1,
        titlle: '退回',
        area: ['500px', '300px'],
        content: html, //这里content是一个普通的String
        btn: ['确定', '取消'],
        btn1: function (index, layero) {
            back = "3";
            var back_reason = $('#back_reason').val();
            if (back_reason == '') {
                layer.msg('退回原因为必填！', {icon: 5, time: 1000});
                return false;
            }
            layer.close(index);
            var productData = getPorductList();
            var all_number = productData.all_number;
            var info = productData.info;
            var exist_price_number = productData.exist_price_number;
            var manage = getManage(inquiry_id, all_number, exist_price_number);
            manage.back_reason = back_reason;
            var params = {
                "async": true,
                "crossDomain": true,
                "url": root.dockingplatform.orderCheckUpdate,
                "method": "POST",
                "headers": {
                    "Content-Type": "application/json"
                },
                "data": JSON.stringify({
                    /*"manage":manage,
                    "info":info,*/
                    "manage": {
                        "back_reason": back_reason,
                        "inquiry_id": inquiry_id,
                    },
                    "info": [],
                    "enterChange": {
                        "inquiry_id": inquiry_id,
                        "back": back,
                        "state": state,
                        "matcher_id": matcher_id,
                        "matching_name": matching_name,
                        "fix_price_id": '',
                        "fix_price_name": ''
                    }
                })
            }

            $.ajax(params).done(function (response) {
                if (response.code == '0') {
                    $('#ReturnReason').modal('hide');
                    $('#Undo').modal('show');
                    layer.msg('该询价单已退回！', {icon: 5, time: 1000});
                } else if (response.code == '60') {
                    layer.msg('该询价单已退回！', {icon: 5, time: 1000});
                } else if (response.code == '70') {
                    layer.msg('该询价单已撤销！', {icon: 5, time: 1000});
                } else {
                    layer.msg('退回失败！', {icon: 5, time: 1000});
                    return false;
                }
                setTimeout(function () {
                    window.parent.doSubmit();
                    var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                    parent.layer.close(index);
                }, 1000);
            });
        }
    });
})

// 添加已有商品
$('#addProduct').click(function () {
    url = 'addproducts.html?receiver_province=' + receiver_province + '&platform=' + platform + '&receiver_city=' + receiver_city + '&customer_id=' + customer_id;
    title = '添加商品';
    goNextPage(title, url);
});

// 添加已有商品
function dataListAdd(product_count, skucodes) {
    addProductBySkuCode('add', skucodes.split(','), product_count, '');
}

function goNextPage(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

//完成匹配
function datalsit(product_countMatch, skucodeMatch, order) {
    addProductBySkuCode('match', skucodeMatch, product_countMatch, order);
}

function addProductBySkuCode(oper, skucode, product_count, order) {
    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.xunjiadan.exportUrl,
        cache: false,  //禁用缓存
        dataType: "json",
        data: JSON.stringify({
            "nowPage": 1,
            "pageSize": 10,
            "model": {
                "skuCode": skucode[0],
                "skuName": '',
                "helpCode": '',
                "cityId": receiver_province,
                "customerId": customer_id
            }
        }),
        success: function (result) {
            console.log(result);
            if (result.errorCode == '0') {
                var data = result.data.list[0];
                var html = '';
                //价格
                if (data.discountPrice) {
                    var discountPrice = data.discountPrice;
                } else {
                    var discountPrice = data.price;
                }
                //小计
                var subtotal = (parseFloat(discountPrice) * parseInt(product_count)).toFixed(2);
                //图片路径
                if (data.imgUrl) {
                    var img_url = data.imgUrl
                } else {
                    var img_url = '';
                }
                if (oper == 'add') {  //添加

                    html += '<tr id="" belong_inquiry_id="' + inquiry_id + '">'
                        + '<td class="rfqg_td1">' + ($('#productList tr').length + 1) + '</td>'
                        + '<td class="rfqg_td2" sku_id="' + data.sku_id + '" spu_id="' + data.spu_id + '">' + data.sku_code + '</td>'
                        + '<td class="rfqg_td3">' + data.sku_name + ' ' + data.sale_attri_value + '</td>'
                        + '<td class="rfqg_td4">' + data.sku_name + ' ' + data.sale_attri_value + '</td>'
                        + '<td class="rfqg_td5">' + data.categoryName + '</td>'
                        + '<td class="rfqg_td6">' + data.brand + '</td>'
                        + '<td class="rfqg_td7">' + '<img src="' + img_url + '"/>' + data.sale_attri_value + '</td>'
                        + '<td class="rfqg_td8"><input maxlength="120" value =""/></td>'
                        + '<td class="rfqg_td9" price="">' + discountPrice + '</td>'
                        + '<td class="rfqg_td10">' + '<div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan" maxlength="5" type="text" class="num_text Numberwo" value="' + product_count + '"></div>' + '</td>'
                        + '<td class="rfqg_td11">' + data.unit + '</td>'
                        + '<td class="rfqg_td12">' + subtotal + '</td>'
                     //   + '<td class="rfqg_td13" product_cycle="">' + '<input class="workinput wicon input-text radius"  type="text" placeholder="要求到货时间" readonly />' + '</td>'
                     //   + '<td class="rfqg_td14" created_time="" update_time="">' + '<input class="workinput wicon input-text radius" style="width: 129px;"  value="" type="text" placeholder="要求采购时间" readonly>' + '</td>'
                        + '<td class="rfqg_td15" info_state="10">' /*+ '<a class="matchProduct" href="javascript:void(0);">匹配商品</a>'*/ + '<a href="javascript:void(0);" class="delProduct">删除</a>' + '</td>'
                        + '</tr>';
                    $('#productList').append(html);
                   /* timeSetMin($('.rfqg_td13>input'));
                    timeSetMin2($('.rfqg_td14>input'));*/
                } else if (oper == 'match') {   // 匹配
                    $('#productList tr').each(function (index, dom) {
                        if ($(dom).find('.rfqg_td1').text() == order) {
                            // 保留的数据 id    序号    商品名称  订货要求   要求到货时间   要求采购时间
                            if ($(dom).find('.rfqg_td2').attr("sku_id") && $(dom).find('.rfqg_td2').attr("sku_id") != '0') {
                                var id = $(dom).attr('id') || '';
                                var product_name = $(dom).find('td.rfqg_td3').text();
                                var order_fillrates = $(dom).find('td.rfqg_td8').text() || '';
                                var claim_arrival_time = $(dom).find('td.rfqg_td13').text();
                                var claim_purchase_time = $(dom).find('td.rfqg_td14 input').val() || '';
                            } else {
                                var id = $(dom).attr('id') || '';
                                if ($(dom).find('.rfqg_td3').children().length > 0) {
                                    var product_name = $(dom).find('td.rfqg_td3 input').val()
                                } else {
                                    var product_name = $(dom).find('td.rfqg_td3').text();
                                }
                                var order_fillrates = $(dom).find('td.rfqg_td8 input').val();
                                var claim_arrival_time = $(dom).find('td.rfqg_td13 input').val();
                                var claim_purchase_time = $(dom).find('td.rfqg_td14 input').val();
                            }
                            if (product_name == '') {
                                product_name = data.sku_name + ' ' + data.sale_attri_value;
                            }
                            html += '<tr id="' + id + '" belong_inquiry_id="">'
                                + '<td class="rfqg_td1">' + order + '</td>'
                                + '<td class="rfqg_td2" sku_id="' + data.sku_id + '" spu_id="' + data.spu_id + '">' + data.sku_code + '</td>'
                                + '<td class="rfqg_td3">' + product_name + '</td>'
                                + '<td class="rfqg_td4">' + data.sku_name + ' ' + data.sale_attri_value + '</td>'
                                + '<td class="rfqg_td5">' + data.categoryName + '</td>'
                                + '<td class="rfqg_td6">' + data.brand + '</td>'
                                + '<td class="rfqg_td7">' + '<img src="' + img_url + '">' + data.sale_attri_value + '</td>'
                                + '<td class="rfqg_td8">' + '<input maxlength="120" value="' + order_fillrates + '"/>' + '</td>'
                                + '<td class="rfqg_td9" price="">' + discountPrice + '</td>'
                                + '<td class="rfqg_td10">' + '<div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan" maxlength="5" type="text"  class="num_text Numberwo" value="' + product_count + '"></div>' + '</td>'
                                + '<td class="rfqg_td11">' + data.unit + '</td>'
                                + '<td class="rfqg_td12">' + subtotal + '</td>'
                             //   + '<td class="rfqg_td13" product_cycle="">' + claim_arrival_time + '</td>'
                               // + '<td class="rfqg_td14" created_time="" update_time="">' + '<input class="workinput wicon input-text radius" style="width: 129px;"  type="text" value="' + claim_purchase_time + '" placeholder="要求采购时间" readonly>' + '</td>'
                                + '<td class="rfqg_td15" info_state="10">'/* + '<a class="matchProduct" href="javascript:void(0);">匹配商品</a>'*/ + '<a href="javascript:void(0);" class="delProduct">删除</a>' + '</td>'
                                + '</tr>';
                            $(dom).replaceWith(html);
                           /* timeSetMin($('.rfqg_td13>input'));
                            timeSetMin2($('.rfqg_td14>input'));*/
                        }
                    });
                }

            }
            sessionStorage.removeItem("skucodeMatch");
            sessionStorage.removeItem("product_countMatch");
            sessionStorage.removeItem("idMatch");
        },
    });
}

function doSave(callback) {
    var productData = getPorductList();
    var all_number = productData.all_number;
    var info = productData.info;
    var exist_price_number = productData.exist_price_number;
    var manage = getManage(inquiry_id, all_number, exist_price_number);
    var orderProductsParams = {
        "async": true,
        "crossDomain": true,
        "url": root.dockingplatform.insertInquiryBill+"?channelId="+$('#ascription_lsit option:selected').val()+"&channelName="+$('#customer_name').val(),
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "data": JSON.stringify({
            "manage": manage,
            "info": info,
            "enterChange": {
                "inquiry_id": inquiry_id,
                "back": '6',
                "state": state,
                "matcher_id": matcher_id,
                "matching_name": matching_name,
                "fix_price_id": '',
                "fix_price_name": ''
            }
        })
    }
    $.ajax(orderProductsParams).done(function (response) {
        callback(response);
    });
}

function getPorductList() {
    var info = [];
    var all_number = 0;
    var exist_price_number = 0;
    for (var i = 0; i < $('#productList>tr').length; i++) {
        var item = $($('#productList>tr')[i]);
        if (item.find('td.rfqg_td2').attr('sku_id') == '0' || item.find('td.rfqg_td2').attr('sku_id') == '') {     // 未匹配
            if (item.find('.rfqg_td7').children().length > 1) {
                var desc = item.find('.rfqg_td7 input').val();
            } else {
                var desc = item.find('.rfqg_td7').text();
            }
            var pic = item.find('.rfqg_td7 img').attr('src');
            var product_depict = JSON.stringify({"desc": desc, "pic": pic});

            if (item.find('.rfqg_td3').children().length > 0) {
                var product_name = item.find('.rfqg_td3 input').val();
            } else {
                var product_name = item.find('.rfqg_td3').text();
            }
            var obj = {
                id: item.attr('id')||'0',
                belong_inquiry_id: inquiry_id,
                sku_id: item.find('td.rfqg_td2').attr('sku_id'),
                spu_id: item.find('td.rfqg_td2').attr('spu_id'),
                sku_code: item.find('td.rfqg_td2').text(),
                product_name: product_name,
                sku_name: item.find('.rfqg_td4 input').val(),
                product_clatemporaryAddssify: item.find('.rfqg_td5 input').val(),
                product_classify: item.find('.rfqg_td5 input').val(),
                brand: item.find('.rfqg_td6 input').val(),
                product_depict: product_depict,
                order_fillrates: item.find('.rfqg_td8 input').val(),
                price: item.find('td.rfqg_td9').attr('price'),
                discount_price: item.find('td.rfqg_td9').text(),
                product_count: item.find('.rfqg_td10 input').val(),
                unit_name: item.find('.rfqg_td11 input').val(),
                subtotal: item.find('td.rfqg_td12').text(),
                product_cycle: '',
                claim_arrival_time: $('#timemin').val(),
                claim_purchase_time: $('#timemax').val(),
                info_state: item.find('.rfqg_td15').attr('info_state'),
                //product_classify: item.find('td.rfqg_td5').text(),
            };
        } else {   // 已匹配
            if (item.find('td.rfqg_td15').attr('info_state') == '10') {
                exist_price_number++;
            }
            var desc = item.find('.rfqg_td7').text();
            var pic = item.find('.rfqg_td7 img').attr('src');
            var product_depict = JSON.stringify({"desc": desc, "pic": pic});
            var obj = {
                id: item.attr('id')||'0',
                belong_inquiry_id: inquiry_id,
                sku_id: item.find('td.rfqg_td2').attr('sku_id'),
                spu_id: item.find('td.rfqg_td2').attr('spu_id'),
                sku_code: item.find('td.rfqg_td2').text(),
                product_name: item.find('td.rfqg_td3').text(),
                sku_name: item.find('td.rfqg_td4').text(),
                product_classify: item.find('td.rfqg_td5').text(),
                brand: item.find('td.rfqg_td6').text(),
                product_depict: product_depict,
                order_fillrates: item.find('.rfqg_td8 input').val(),
                price: item.find('td.rfqg_td9').attr('price'),
                discount_price: item.find('td.rfqg_td9').text(),
                product_count: item.find('.rfqg_td10 input').val(),
                unit_name: item.find('td.rfqg_td11').text(),
                subtotal: item.find('td.rfqg_td12').text(),
                product_cycle:"1", /*item.find('td.rfqg_td13').attr('product_cycle')*/
                claim_arrival_time: $('#timemin').val(),
                claim_purchase_time: $('#timemax').val(),
                info_state: item.find('.rfqg_td15').attr('info_state')
            };
        }
        info.push(obj);
        if (item.find('td.rfqg_td15').attr('info_state') != '20') {
            all_number++;
        }
    }
    ;
    return {
        info: info,
        all_number: all_number,
        exist_price_number: exist_price_number
    }
}



function getManage(inquiry_id, all_number, exist_price_number) {
    console.log($('#getCountry option:selected').data('down'));
    var getCountry = "";
    if($('#getCountry option:selected').data('down')==null || $('#getCountry option:selected').data('down')=='' || $('#getCountry option:selected').data('down')==undefined){
        getCountry=""
    }else {
        getCountry=$('#getCountry option:selected').data('down')
    }
    var manage = {
        "inquiry_id": inquiry_id,
        "all_number": all_number,
        "exist_price_number": exist_price_number,
        "inquiry_name": "",
        "customer_id": sessionStorage.getItem("choosecustomerId"),
        "customer_name": sessionStorage.getItem("choosecustomerName"),
        "customer_code": sessionStorage.getItem("choosecustomerCode"),
        "login_account": JSON.parse(web.readCookie("loginData")).user.user_ID,
        "member_id": "",
        "linkman": $('#linkman').val(),
        "linkman_phone": $('#linkman_phone').val(),
        "receiver_province": $('#getArea option:selected').val(),
        "receiver_province_id":$('#getArea option:selected').data('down'),
        "receiver_province_name": $('#getArea option:selected').text(),
        "receiver_city": $('#getPlace option:selected').val(),
        "receiver_city_id": $('#getPlace option:selected').data('down'),
        "receiver_city_name": $('#getPlace option:selected').text(),
        "receiver_area": $('#getCity option:selected').val(),
        "receiver_area_id": $('#getCity option:selected').data('down'),
        "receiver_area_name": $('#getCity option:selected').text(),
        "street":$('#getCountry option:selected').val(),
        "street_id":getCountry,
        "street_name":$('#getCountry option:selected').text(),
        "detail_address": "",
        "inquiry_status": "",
        "back_reason": "",
        "other_explain": $('#other_explain').val(),
        "inquiry_time": "",
        "matcher_id": "",
        "matching_name": "",
        "matching_time": "",
        "fix_price_id": "",
        "fix_price_name": "",
        "fix_price_time": "",
        "platform":"30",
        "ship_add_id":"",
        "source":"10",
        "organization_name":sessionStorage.getItem("choosebelongGroupName"),
        "claim_arrival_time":  $('#timemin').val(),
        "claim_purchase_time":$('#timemax').val()
    };
    return manage;
}

function getNowDate() {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth()+1;
    if(month<10){
        month = '0'+month;
    }
    var day = date.getDate()+1;
    if(day<10){
        day = '0'+day;
    }
    var hours = date.getHours();
    if(hours<9){
        hours = '0'+hours;
    }
    var minutes = date.getMinutes();
    if(minutes<9){
        minutes = '0'+minutes;
    }
    var seconds = date.getSeconds();
    if(seconds<9){
        seconds = '0'+seconds
    }
    return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
}

function goNextPage(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

function timeSet(ele) {
    ele.each(function (index, dom) {
        $.jeDate(dom, {
            format: "YYYY-MM-DD"
        });
    });

}
function timeSet2(ele) {
    ele.each(function (index, dom) {
        $.jeDate(dom, {
            format: "YYYY-MM-DD hh:mm"
        });
    });

}
function timeSetMin(ele) {
    ele.each(function (index, dom) {
        $.jeDate(dom, {
            format: "YYYY-MM-DD",
            minDate:getNowDate(),
            isClear:false,                               //是否显示清空
            isToday:false,
        });
    });

}
function timeSetMin2(ele) {
    ele.each(function (index, dom) {
        $.jeDate(dom,{
            format: 'YYYY-MM-DD hh:mm:ss',
            minDate: $.nowDate().substring(0,$.nowDate().length-8)+"00:00:00",
            clearfun:function(val) {
                start.minDate =$.nowDate().substring(0,$.nowDate().length-8)+"00:00:00";
                start.maxDate ="2099-12-31 23:59:59";
                end.minDate="1900-01-01 00:00:00";
                end.maxDate ="2099-12-31 23:59:59";
            },
        })
    });


}
//批量导入商品
function upLoadFile() {
    $("#fileUp").trigger('click');
}
function putDataToPage() {
    var formData = new FormData();
    formData.append('file', $("#fileUp")[0].files[0]);
    formData.append('inquiryId', inquiry_id);
    $.ajax({
        url:  root.publics.inquiryImportExcelV1,
        cache: false,  //禁用缓存
        type: "POST",
        // 告诉jQuery不要去处理发送的数据
        processData: false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType: false,
        data: formData,
        success: function (data) {
            $('#fileUp').val('');
            console.log(data);
            //var datas= JSON.parse(data);
            //var datas=$.parseJSON(result);
            var datas=eval('(' + data + ')');


            console.log(datas.code);

            if(datas.code=="0"){
                console.log(123123);
                //for(var i=0;i<datas.data.length;i++)  {
                $.each(datas.data, function (i, field) {
                    if (field.product_name==undefined || field.product_name=='' || field.product_name==null){
                        return false;
                    }
                    var time="";
                    if (field.time!="1000-01-01") {
                        time=field.time;
                    }
                    var html = '';
                    html += '<tr id="" belong_inquiry_id="' + inquiry_id + '">'
                        + '<td class="rfqg_td1">' + ($('#productList tr').length + 1) + '</td>' //序号
                        + '<td class="rfqg_td2" sku_id="" spu_id=""></td>'  //商品编码
                        + '<td class="rfqg_td3"><input value="' + field.product_name + '"/></td>'   //商品名称
                        + '<td class="rfqg_td4"><input value="' + field.sku_name + '" /></td>'   //平台商品名称
                        + '<td class="rfqg_td5"><input value="' + field.product_classify + '" /></td>'   //分类
                        + '<td class="rfqg_td6"><input value="' + field.brand + '"/></td>'   //品牌
                        + '<td class="rfqg_td7"><img src = ""/><input value="' + field.product_text + '"/></td>'  //商品描述
                        + '<td class="rfqg_td8"><input value="' + field.order_fillrates + '"  maxlength="60"/></td>'  //订货要求
                        + '<td class="rfqg_td9" price=""></td>'   //价格
                        + '<td class="rfqg_td10">' + '<div class="numberbar"><span onclick="number_decrease(this)" class="number_decrease">-</span><span onclick="number_increase(this)" class="number_increase">+</span><input id="Smallplan" maxlength="5" value="' + field.product_Number + '" type="text"  class="num_text Numberwo" value="' + '' + '"></div>' + '</td>'
                        + '<td class="rfqg_td11"><input class="focus" value="' + field.unit + '"/></td>'  //单位
                        + '<td class="rfqg_td12"></td>'  //小计
                     //   + '<td class="rfqg_td13" product_cycle=""><input class="workinput wicon input-text radius focus" type="text" value="' + time + '" placeholder="要求到货时间" readonly></td>'
                     //   + '<td class="rfqg_td14" created_time=""><input class="workinput wicon input-text radius focus" style="width: 129px;" type="text" placeholder="要求采购时间" readonly></td>'
                        + '<td class="rfqg_td15" info_state="10"><!--<a class="matchProduct" href="javascript:void(0); ">匹配商品</a>--><a class="delProduct" href="javascript:void(0);">删除</a></td>'
                        + '</tr>';
                    $('#productList').append(html);
                   /* timeSetMin($('.rfqg_td13>input'));
                    timeSetMin2($('.rfqg_td14>input'));*/

                });


                // }
            }
            else {
                $.Huimodalalert(datas.message,2000);
            }

        }
    });

}